package algotithm.weekendrace.leetcode227.test3;

/**
 * @author zhouyanxiang
 * @Date 2021-02-2021/2/7-18:19
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        String word1 = "cabaa";
        String word2 = "bcaaa";
        String s = solution.largestMerge(word1, word2);
        System.out.println(s);
    }

    public String largestMerge(String word1, String word2) {
        word1 += (char)('a' - 1);
        word2 += (char)('a' - 1);
        StringBuilder sb = new StringBuilder();
        char[] c1 = word1.toCharArray(), c2 = word2.toCharArray();
        int n = c1.length, m = c2.length;
        int s1 = 0,s2 = 0;
//        System.out.println(word1 + " " + word2);
        while(s1 < n && s2 < m){
            if(word1.substring(s1).compareTo(word2.substring(s2)) > 0) {
                sb.append(c1[s1++]);
            } else {
                sb.append(c2[s2++]);
            }
        }
        return sb.substring(0, n + m - 2);
    }

}
